package pe.edu.upc.dsd.epica.util;

import java.util.List;

import pe.edu.upc.dsd.epica.R;
import pe.edu.upc.dsd.epica.model.Establecimiento;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class EstablecimientoAdapter extends ArrayAdapter<Establecimiento> {

	int resource;
	String response;
	Context context; // Initialize adapter

	public EstablecimientoAdapter(Context context, int resource, List<Establecimiento> items) {
		super(context, resource, items);
		this.resource = resource;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout estaView;
		// Get the current alert object
		Establecimiento est = getItem(position);

		if (convertView == null) {
			estaView = new LinearLayout(getContext());
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater vi;
			vi = (LayoutInflater) getContext().getSystemService(inflater);
			vi.inflate(resource, estaView, true);
		} else {
			estaView = (LinearLayout) convertView;
		}

		TextView estaText = (TextView) estaView
				.findViewById(R.id.txtDescripcion);

		estaText.setText(est.getDescripcion());
		return estaView;
	}

}
